<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="指标编号" prop="zbbh">
        <el-input
          v-model="queryParams.zbbh"
          placeholder="请输入指标编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指标名称" prop="zbmc">
        <el-input
          v-model="queryParams.zbmc"
          placeholder="请输入指标名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ysgj:zbk:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ysgj:zbk:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ysgj:zbk:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ysgj:zbk:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="zbkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :show-overflow-tooltip="true" width="180"  label="主键" align="center" prop="id" />
      <el-table-column label="指标类型：01-涉税核算类，02-财务核算" align="center" prop="zbFl" />
      <el-table-column label="视角维度" align="center" prop="sjwdCode" />
      <el-table-column label="业务分类" align="center" prop="ywflCode" />
      <el-table-column label="业务分类子类" align="center" prop="ywflZCode" />
      <el-table-column label="1级指标，2级指标，3级指标" align="center" prop="zbcj" />
      <el-table-column :show-overflow-tooltip="true" label="指标编号" align="center" prop="zbbh" />
      <el-table-column :show-overflow-tooltip="true" label="指标名称" align="center" prop="zbmc" />
      <el-table-column :show-overflow-tooltip="true" label="其它名称" align="center" prop="qtmc" />
      <el-table-column :show-overflow-tooltip="true" label="科目" align="center" prop="km" />
      <el-table-column :show-overflow-tooltip="true" label="指标定义" align="center" prop="zbdy" />
      <el-table-column :show-overflow-tooltip="true" label="风险业务明细" align="center" prop="fxywsxbt" />
      <el-table-column :show-overflow-tooltip="true" label="适用范围" align="center" prop="syfw" />
      <el-table-column :show-overflow-tooltip="true" label="指标公式" align="center" prop="zbgs" />
      <el-table-column :show-overflow-tooltip="true" label="指标数据表单来源" align="center" prop="zbsjly" />
      <el-table-column :show-overflow-tooltip="true" label="指标说明" align="center" prop="zbsm" />
      <el-table-column :show-overflow-tooltip="true" label="风险提示" align="center" prop="jgfxts" />
      <el-table-column :show-overflow-tooltip="true" label="应对方案(局端)" align="center" prop="fxydfaJd" />
      <el-table-column :show-overflow-tooltip="true" label="应对方案" align="center" prop="fxydfa" />
      <el-table-column :show-overflow-tooltip="true" label="风险描述" align="center" prop="fxms" />
      <el-table-column :show-overflow-tooltip="true" label="相关知识" align="center" prop="xgzs" />
      <el-table-column :show-overflow-tooltip="true" label="是否收费,0免费、1收费" align="center" prop="ifSf" />
      <el-table-column :show-overflow-tooltip="true" label="重点指标标记" align="center" prop="gwfx" />
      <el-table-column :show-overflow-tooltip="true" label="排序号" align="center" prop="xh" />
      <el-table-column :show-overflow-tooltip="true" label="点击量" align="center" prop="djl" />
      <el-table-column :show-overflow-tooltip="true" label="规则描述" align="center" prop="gzms" />
      <el-table-column :show-overflow-tooltip="true" label="1-存储过程，2-函数，3-程序，4-xml 5-配置sql" align="center" prop="gzwjLx" />
      <el-table-column :show-overflow-tooltip="true" label="规则文件" align="center" prop="gzwj" />
      <el-table-column :show-overflow-tooltip="true" label="启用标志 0启用1 停用" align="center" prop="qybs" />
      <el-table-column :show-overflow-tooltip="true" label="启用时间" align="center" prop="qysj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.qysj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="modifiDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifiDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="删除标识,0,正常，1-删除" align="center" prop="bsblag" />
      <el-table-column label="指标批次" align="center" prop="zbpc" />
      <el-table-column label="指标来源,01-优税管家，02-局端,3-新增指标" align="center" prop="zbly" />
      <el-table-column label="只是图谱入口" align="center" prop="glzbBh" />
      <el-table-column label="风险标记：01-风险指标　02-计算指标" align="center" prop="fxbjDm" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ysgj:zbk:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ysgj:zbk:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改指标库对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="指标类型：01-涉税核算类，02-财务核算" prop="zbFl">
          <el-input v-model="form.zbFl" placeholder="请输入指标类型：01-涉税核算类，02-财务核算" />
        </el-form-item>
        <el-form-item label="视角维度" prop="sjwdCode">
          <el-input v-model="form.sjwdCode" placeholder="请输入视角维度" />
        </el-form-item>
        <el-form-item label="业务分类" prop="ywflCode">
          <el-input v-model="form.ywflCode" placeholder="请输入业务分类" />
        </el-form-item>
        <el-form-item label="业务分类子类" prop="ywflZCode">
          <el-input v-model="form.ywflZCode" placeholder="请输入业务分类子类" />
        </el-form-item>
        <el-form-item label="1级指标，2级指标，3级指标" prop="zbcj">
          <el-input v-model="form.zbcj" placeholder="请输入1级指标，2级指标，3级指标" />
        </el-form-item>
        <el-form-item label="指标编号" prop="zbbh">
          <el-input v-model="form.zbbh" placeholder="请输入指标编号" />
        </el-form-item>
        <el-form-item label="指标名称" prop="zbmc">
          <el-input v-model="form.zbmc" placeholder="请输入指标名称" />
        </el-form-item>
        <el-form-item label="其它名称" prop="qtmc">
          <el-input v-model="form.qtmc" placeholder="请输入其它名称" />
        </el-form-item>
        <el-form-item label="科目" prop="km">
          <el-input v-model="form.km" placeholder="请输入科目" />
        </el-form-item>
        <el-form-item label="指标定义" prop="zbdy">
          <el-input v-model="form.zbdy" placeholder="请输入指标定义" />
        </el-form-item>
        <el-form-item label="风险业务明细" prop="fxywsxbt">
          <el-input v-model="form.fxywsxbt" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="适用范围" prop="syfw">
          <el-input v-model="form.syfw" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="指标公式" prop="zbgs">
          <el-input v-model="form.zbgs" placeholder="请输入指标公式" />
        </el-form-item>
        <el-form-item label="指标数据表单来源" prop="zbsjly">
          <el-input v-model="form.zbsjly" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="指标说明" prop="zbsm">
          <el-input v-model="form.zbsm" placeholder="请输入指标说明" />
        </el-form-item>
        <el-form-item label="风险提示" prop="jgfxts">
          <el-input v-model="form.jgfxts" placeholder="请输入风险提示" />
        </el-form-item>
        <el-form-item label="应对方案(局端)" prop="fxydfaJd">
          <el-input v-model="form.fxydfaJd" placeholder="请输入应对方案(局端)" />
        </el-form-item>
        <el-form-item label="应对方案" prop="fxydfa">
          <el-input v-model="form.fxydfa" placeholder="请输入应对方案" />
        </el-form-item>
        <el-form-item label="风险描述" prop="fxms">
          <el-input v-model="form.fxms" placeholder="请输入风险描述" />
        </el-form-item>
        <el-form-item label="相关知识" prop="xgzs">
          <el-input v-model="form.xgzs" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否收费,0免费、1收费" prop="ifSf">
          <el-input v-model="form.ifSf" placeholder="请输入是否收费,0免费、1收费" />
        </el-form-item>
        <el-form-item label="重点指标标记" prop="gwfx">
          <el-input v-model="form.gwfx" placeholder="请输入重点指标标记" />
        </el-form-item>
        <el-form-item label="排序号" prop="xh">
          <el-input v-model="form.xh" placeholder="请输入排序号" />
        </el-form-item>
        <el-form-item label="点击量" prop="djl">
          <el-input v-model="form.djl" placeholder="请输入点击量" />
        </el-form-item>
        <el-form-item label="规则描述" prop="gzms">
          <el-input v-model="form.gzms" placeholder="请输入规则描述" />
        </el-form-item>
        <el-form-item label="1-存储过程，2-函数，3-程序，4-xml 5-配置sql" prop="gzwjLx">
          <el-input v-model="form.gzwjLx" placeholder="请输入1-存储过程，2-函数，3-程序，4-xml 5-配置sql" />
        </el-form-item>
        <el-form-item label="规则文件" prop="gzwj">
          <el-input v-model="form.gzwj" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="启用标志 0启用1 停用" prop="qybs">
          <el-input v-model="form.qybs" placeholder="请输入启用标志 0启用1 停用" />
        </el-form-item>
        <el-form-item label="启用时间" prop="qysj">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.qysj"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择启用时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="modifiDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.modifiDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择修改时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识,0,正常，1-删除" prop="bsblag">
          <el-input v-model="form.bsblag" placeholder="请输入删除标识,0,正常，1-删除" />
        </el-form-item>
        <el-form-item label="指标批次" prop="zbpc">
          <el-input v-model="form.zbpc" placeholder="请输入指标批次" />
        </el-form-item>
        <el-form-item label="指标来源,01-优税管家，02-局端,3-新增指标" prop="zbly">
          <el-input v-model="form.zbly" placeholder="请输入指标来源,01-优税管家，02-局端,3-新增指标" />
        </el-form-item>
        <el-form-item label="只是图谱入口" prop="glzbBh">
          <el-input v-model="form.glzbBh" placeholder="请输入只是图谱入口" />
        </el-form-item>
        <el-form-item label="风险标记：01-风险指标　02-计算指标" prop="fxbjDm">
          <el-input v-model="form.fxbjDm" placeholder="请输入风险标记：01-风险指标　02-计算指标" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZbk, getZbk, delZbk, addZbk, updateZbk, exportZbk } from "@/api/ysgj/zbk";

export default {
  name: "Zbk",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 指标库表格数据
      zbkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zbbh: undefined,
        zbmc: undefined,
        createDate: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        zbFl: [
          { required: true, message: "指标类型：01-涉税核算类，02-财务核算不能为空", trigger: "blur" }
        ],
        zbcj: [
          { required: true, message: "1级指标，2级指标，3级指标不能为空", trigger: "blur" }
        ],
        zbbh: [
          { required: true, message: "指标编号不能为空", trigger: "blur" }
        ],
        zbmc: [
          { required: true, message: "指标名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询指标库列表 */
    getList() {
      this.loading = true;
      listZbk(this.queryParams).then(response => {
        this.zbkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        zbFl: undefined,
        sjwdCode: undefined,
        ywflCode: undefined,
        ywflZCode: undefined,
        zbcj: undefined,
        zbbh: undefined,
        zbmc: undefined,
        qtmc: undefined,
        km: undefined,
        zbdy: undefined,
        fxywsxbt: undefined,
        syfw: undefined,
        zbgs: undefined,
        zbsjly: undefined,
        zbsm: undefined,
        jgfxts: undefined,
        fxydfaJd: undefined,
        fxydfa: undefined,
        fxms: undefined,
        xgzs: undefined,
        ifSf: undefined,
        gwfx: undefined,
        xh: undefined,
        djl: undefined,
        gzms: undefined,
        gzwjLx: undefined,
        gzwj: undefined,
        qybs: undefined,
        qysj: undefined,
        createDate: undefined,
        modifiDate: undefined,
        bsblag: undefined,
        zbpc: undefined,
        zbly: undefined,
        glzbBh: undefined,
        fxbjDm: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加指标库";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZbk(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改指标库";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateZbk(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addZbk(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除指标库编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delZbk(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有指标库数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportZbk(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
